/**
*      author: Y_Yao
*      created: 2025-03-23 14:28:01
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 1e3 + 7;
int n;
int a[N];

int gcd(int a,int b)
{
    if(b == 0) return a;
    else return gcd(b,a % b);
}


void solve()
{
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    int m = a[1];
    for(int i = 1;i <= n;i++)
    {
        m = gcd(m,a[i]);
    }
    
    int ans = 0;
    for(int i = 1;i <= n;i++)
    {
        int tmp = a[i] / m;
        while(tmp % 2 == 0)
        {
            tmp /= 2;
            ans++;
        }
        while(tmp % 3 == 0)
        {
            tmp /= 3;
            ans++;
        }
        if(tmp != 1)
        {
            cout << -1 << endl;
            return;
        }
    }
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}